﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebUI.Areas.Bots.Models;
using DAL;
using Entities;

namespace WebUI.Areas.Bots.Controllers
{
    public partial class BotTypeController : BaseController
    {

        #region Constructor

        public BotTypeController(ISessionHelper sessionHelper)
            : base(sessionHelper)
        {
        }

        #endregion

        #region Action Methods

        public virtual ViewResult Index()
        {
            BotTypeViewModel model = new BotTypeViewModel
            {
                SelectedType = _sessionHelper.Bot.BotType
            };

            return View(model);
        }

        [HttpPost]
        public virtual ActionResult Save(BotTypeViewModel model)
        {
            if (ModelState.IsValid)
            {
                _sessionHelper.Bot.BotType = model.SelectedType;

                if (model.SelectedType == (short)BotType.BasicFiltering)
                {
                    return RedirectToRoute(new { action = MVC.Bots.Schedule.ActionNames.Index, controller = MVC.Bots.Schedule.Name, step = MVC.Bots.Schedule.Name });
                }
                else
                {
                    return RedirectToRoute(new { action = "Index", controller = MVC.Bots.AdvancedBotType.Name, step = MVC.Bots.BotType.Name });
                }
            }

            return View(MVC.Bots.BotType.ActionNames.Index, model);
        }

        #endregion
    }
}